package ctype

import (
	"bp/internal/util"
	"database/sql/driver"
	"fmt"
	"strings"
)

type ItemCategoryConfiguration struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

type ItemCategoryConfigurationArray []ItemCategoryConfiguration

// Scan implements the Scanner interface.
func (icc *ItemCategoryConfiguration) Scan(value interface{}) error {
	fmt.Printf("icc=>%v,%s", value, string(value.([]byte)))
	str := string(value.([]byte))
	val := str[1 : len(str)-1]
	vals := strings.Split(val, ",")
	icc.ID = util.StringToInt64(vals[0])
	icc.Name = vals[1]
	return nil
}

// Value implements the driver Valuer interface.
func (icc ItemCategoryConfiguration) Value() (driver.Value, error) {
	return fmt.Sprintf("(%d,%s)", icc.ID, icc.Name), nil
}
